package beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;


@Entity
@Table(name="facturas")
public class FacturaBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)	
	@Column(name="idFactura",nullable=false)
	private int numero;
	
	@Column(name="fecha")
	private Date fecha;
	
	@OneToOne
	@JoinColumn(name="idVenta")
	private VentaBean venta;
	
	@Column(name="total")
	private float total;
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@Fetch(FetchMode.SUBSELECT)
	@JoinColumn(name="idFactura")
	private List<ItemFacturaBean> items;
	
	public FacturaBean(){
		this.items=new ArrayList<ItemFacturaBean>();
	}
	
	public int getNumero() {
		return numero;
	}
	public void setNumero(int numero) {
		this.numero = numero;
	}
	public Date getFecha() {
		return fecha;
	}
	public void setFecha(Date fecha) {
		this.fecha = fecha;
	}
	public VentaBean getVenta() {
		return venta;
	}
	public void setVenta(VentaBean venta) {
		this.venta = venta;
	}
	public float getTotal() {
		return total;
	}
	public void setTotal(float total) {
		this.total = total;
	}
	public List<ItemFacturaBean> getItems() {
		return items;
	}
	public void setItems(List<ItemFacturaBean> items) {
		this.items = items;
	}
	
	
}
